{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 模糊综合评判法\n",
    "1. 一级模糊综合评判(375页)\n",
    "    1. 确定因素集 U = {u_1, u_2, ..., u_n}\n",
    "    2. 确定评语集 V = {v_1, v_2, ..., v_m}. 如优秀, 良好, 一般, 较差, 差.\n",
    "    3. 确定各因素权重 A = [a_1, a_2, ..., a_n]. 一般方法有: Delphi法, 加权平均法, 众人评估法等\n",
    "    4. 确定模糊综合评判矩阵 R\n",
    "    5. 评判结果: B=A·R\n",
    "2. 多层次模糊综合评判\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "综合评语为:  [0.175 0.53  0.275 0.02  0.   ]\n",
      "按照选取数值最大的原则, 得到最终评判结果为:  良好\n"
     ]
    }
   ],
   "source": [
    "# 一级模糊综合评判\n",
    "# U = ['政治表现', '工作能力', '工作态度', '工作成绩']\n",
    "# V = ['优秀', '良好', '一般', '较差', '差']\n",
    "# A = [0.25, 0.2, 0.25, 0.3]\n",
    "# 群众打分中, 分别有 10%, 50%, 40%, 0%, 0% 的人认为政治表现 优秀, 良好, 一般, 较差, 差\n",
    "# 因此, R[0] = [0.1, 0.5, 0.4, 0., 0.]\n",
    "# 以此类推.\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "V = ['优秀', '良好', '一般', '较差', '差']\n",
    "# 权重\n",
    "A = [0.25, 0.2, 0.25, 0.3]\n",
    "# 模糊综合评判矩阵\n",
    "R = [[0.1, 0.5, 0.4, 0.0, 0.0],\n",
    "     [0.2, 0.5, 0.2, 0.1, 0.0],\n",
    "     [0.2, 0.5, 0.3, 0.0, 0.0],\n",
    "     [0.2, 0.6, 0.2, 0.0, 0.0]]\n",
    "B = np.matmul(A, R)\n",
    "print('综合评语为: ', B)\n",
    "print('按照选取数值最大的原则, 得到最终评判结果为: ', V[np.argmax(B)])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "综合评语为:  [0.288  0.354  0.2355 0.0865 0.036 ]\n",
      "按照选取数值最大的原则, 得到最终评判结果为:  良好\n"
     ]
    }
   ],
   "source": [
    "# 多层次模糊综合评判\n",
    "# 一级指标权重: \n",
    "A = [0.4, 0.3, 0.2, 0.1]\n",
    "# 二级指标权重: \n",
    "AA = [[0.2, 0.3, 0.3, 0.2],\n",
    "      [0.3, 0.2, 0.1, 0.2, 0.2],\n",
    "      [0.1, 0.2, 0.3, 0.2, 0.2],\n",
    "      [0.3, 0.2, 0.2, 0.3]]\n",
    "\n",
    "# 获取每一小项的评语\n",
    "R = np.loadtxt('14.D 多层次模糊综合评判数据.txt') \n",
    "R1 = R[:4]\n",
    "R2 = R[4:9]\n",
    "R3 = R[9:14]\n",
    "R4 = R[14:]\n",
    "\n",
    "# 计算每一大项的评语\n",
    "R = np.array([np.matmul(AA[0], R1), \n",
    "              np.matmul(AA[1], R2),\n",
    "              np.matmul(AA[2], R3),\n",
    "              np.matmul(AA[3], R4)])\n",
    "B = np.matmul(A, R)\n",
    "print('综合评语为: ', B)\n",
    "print('按照选取数值最大的原则, 得到最终评判结果为: ', V[np.argmax(B)])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
